//
//  HJBaseTableViewController.swift
//  HJWeiBo
//
//  Created by 黄珏 on 15/10/26.
//  Copyright © 2015年 黄珏. All rights reserved.
//

import UIKit

class HJBaseTableViewController: UITableViewController {
    var userLogin = HJUserAccount.isUerLogin
    override func loadView() {
        /**
        判断用户是否登入
        */
        userLogin ? super.loadView() : setupView()
    }
    var vistorView: HJVistorView?
    func setupView(){
        vistorView = HJVistorView()
        view = vistorView
        vistorView!.backgroundColor = UIColor(white: 237 / 256, alpha: 1)
        vistorView?.vistorViewDelegate = self
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登入", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewlogin")
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewRegister")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if self is HJHomeTableViewController {
            //添加动画
            vistorView?.addCoreAnimation()
            //添加通知
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "becomeActivite", name: UIApplicationDidBecomeActiveNotification, object: nil)
        }else if self is HJMessageTableViewController {
            //改变界面内容
            vistorView?.setupViewContent("  登录后，别人评论你的微博，发给你的消息，都会在这里收到通知", iconName: "visitordiscover_image_message")
        }else if self is HJDiscoverTableViewController {
            vistorView?.setupViewContent("  登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过", iconName: "visitordiscover_image_message")
        }else if self is HJProfileTableViewController {
            vistorView?.setupViewContent("  登录后，你的微博、相册、个人资料会显示在这里，展示给别人", iconName: "visitordiscover_image_profile")
        }
    }
    
    func didEnterBackground() {
        vistorView?.pauseAnimation()
    }
    func becomeActivite() {
        vistorView?.resumeAnimation()
    }
}

extension HJBaseTableViewController: HJVistorViewDelegate {
    func vistorViewlogin() {
        let newVC = HJoauthVCViewController()
        presentViewController(UINavigationController(rootViewController: newVC), animated: true, completion: nil)
        
    }

    func vistorViewRegister() {
        print(__FUNCTION__)
    }
}
